/*******************************************************************************
 * Copyright (c) 2005, 2014 springside.github.io
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package com.sdgakj.repository;

import com.sdgakj.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.List;

public interface UserDao extends PagingAndSortingRepository<User, Long>,JpaSpecificationExecutor<User> {
	
	User findByLoginName(String loginName);
	
 	@Query(value = " from User u where u.loginName=?1 and u.type =?2 and u.deltag=?3")
	User findAdminByLoginName(String loginName, String type, String deltag);
 	
 	/**
 	 * 这个方法是为了让录入数据的人有个权限
 	 * @param loginName
 	 * @param type
 	 * @return
 	 */
 	@Query(value = " from User u where u.loginName=?1 and u.type !=?2")
	User findAdminNotUser(String loginName, String type);
 	
	@Query(value = "from User u where u.mobile = ?1 and u.id != ?2 ")
	User findByMobileAndUserId(String mobile, Long userId);

	@Query(value = "from User u where u.mobile = ?1")
	User findByMobile(String mobile);
	/*
	* 通过微信用的openid查找用户
	* */
	@Query(value = "select * from f_user where openid=?1",nativeQuery = true)
	User findUserByOpenid(String openid);

	@Query(value = "select * from f_user where point!='0' order by point desc",nativeQuery = true)
	List<User> getPointOredrByUserId();

	/*
	* 通过微信注册用户
	* **/
	/*@Query(value = "insert into f_user (loginName,password,type,register_date,deltag,sex,openid) values (?1,?2,?3,?4,?5,?6,?7)",nativeQuery = true)
	User saveUserByweixin(String loginName,String pwd,String type,String registerDate,String deltag,String sex,String openid);*/

}
